//
//  LJJMyViewController.m
//  shopTest
//
//  Created by 梁佳佳 on 2016/11/14.
//  Copyright © 2016年 梁佳佳. All rights reserved.
//

#import "LJJMyViewController.h"
#import "LJJMyHeadView.h"
#import "LJJMyTableView.h"
#import "LJJLoginViewController.h"
#import "LJJRegistViewController.h"

@interface LJJMyViewController ()

@property (strong, nonatomic) LJJMyHeadView *headView;    /** 头部视图 **/
@property (strong, nonatomic) LJJMyTableView *tableView;    /** 展示功能的表格 **/

@end

@implementation LJJMyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = MAINCOLOR;
    self.edgesForExtendedLayout = 0;
    [self configUI];
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self reloadUI];//刷新
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
#pragma mark -
#pragma mark - method
- (void)configUI
{
    [self.view addSubview:self.tableView];
}
- (void)reloadUI
{
    [self.tableView reloadData];
    [self.headView reloadHeadView];
}
#pragma mark -
#pragma mark - lazy method
- (LJJMyHeadView *)headView
{
    if (!_headView) {
        _headView = [[LJJMyHeadView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 160)];
        __weak typeof(self) weakSelf = self;
        _headView.loginBlock = ^(){
            LJJLoginViewController *loginVC = [[LJJLoginViewController alloc] init];
            [weakSelf.navigationController pushViewController:loginVC animated:YES];
        };
        _headView.registBlock = ^(){
            LJJRegistViewController *registVC = [[LJJRegistViewController alloc] init];
            [weakSelf.navigationController pushViewController:registVC animated:YES];
        };
    }
    return _headView;
}

- (LJJMyTableView *)tableView
{
    if (!_tableView) {
        _tableView = [[LJJMyTableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) style:UITableViewStylePlain];
        _tableView.tableHeaderView = self.headView;
        __weak typeof(self) weakSelf = self;
        _tableView.exitBlock = ^{
            [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"ISLOGIN"];
            [weakSelf reloadUI];
        };
    }
    return _tableView;
}

@end
